package Fragment;

import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.zelonghu.test_all_without_network.AppContent;
import com.example.zelonghu.test_all_without_network.R;
import java.util.Iterator;
import java.util.List;
import SQLUtils.sqllite;
import SensorData.SensorData;

/**
 * Created by zelonghu on 2019/4/12.
 */

public class ShowFragment extends Fragment {
    TextView textView = null;
    List<SensorData> sdl= null;
    SQLiteDatabase db = null;
    String dbtablename = null;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        db= SQLiteDatabase.openOrCreateDatabase(getContext().getFilesDir().getPath()+"/sql.db",null);
        dbtablename = AppContent.tablename;
        Log.i("test","show layout");
        View view=inflater.inflate(R.layout.showfragment_layout,container,false);
        textView = (TextView) view.findViewById(R.id.textview);

        return view;
    }

    @Override
    public void onResume() {
        super.onResume();
        Thread thread = new Thread(){
            @Override
            public void run() {
                try {
                    sdl = sqllite.querySDDesc(db, dbtablename);
                    StringBuffer sb = new StringBuffer();
                    Iterator i = sdl.iterator();
                    while (i.hasNext()) {
                        sb.append(i.next().toString());
                    }
                    Log.i("settext", "");
                    textView.setText(sb.toString());
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        };
        thread.run();
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }
}
